package com.hualan.sfzyproject.controller.admin;

import com.hualan.sfzyproject.domain.CharityActivity;
import com.hualan.sfzyproject.mapper.CharityActivityMapper;
import com.hualan.sfzyproject.service.CharityActivityService;
import com.hualan.sfzyproject.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/charityActivity")
public class CharityActivityController {
    @Autowired
    public CharityActivityService charityActivityService;
    @Autowired
    public CharityActivityMapper charityActivityMapper;
    @GetMapping("/listAll")
    public R listAll(Integer page, Integer pageSize) {
        return R.ok(charityActivityService.listAll(page,pageSize));
    }
    @GetMapping("/list")
    public R list() {
        return R.ok(charityActivityService.listAllConsultants());
    }
    //根据标题模糊查询
    @GetMapping("/search")
    public R search(String title) {
        return R.ok(charityActivityService.selectByTitle(title));
    }
    //根据咨询师id分类查询
    @GetMapping("/searchByConsultants/{id}")
    public R searchByConsultants(@PathVariable("id") Integer id) {
        return R.ok(charityActivityService.selectById(id));
    }
    //添加
    @PostMapping("/add")
    public R add(@RequestBody CharityActivity charityActivity) {
        return R.ok(charityActivityMapper.insert(charityActivity));
    }
    //删除
    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable("id") Long id) {
        return R.ok(charityActivityMapper.deleteByPrimaryKey(id));
    }
    //批量删除
    @DeleteMapping("/batchDelete")
    public R batchDelete(@RequestParam List<Long> ids) {
        return R.ok(charityActivityMapper.deleteBatch(ids));
    }
    //修改
    @PutMapping("/update")
    public R update(CharityActivity charityActivity) {
        return R.ok(charityActivityMapper.updateByPrimaryKeySelective(charityActivity));
    }
    //详情
    @GetMapping("/detail/{id}")
    public R detail(@PathVariable("id") Long id) {
        return R.ok(charityActivityMapper.selectByPrimaryKey(id));
    }
}
